package com.example.qxfw.dlqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.YbzzForecastFinal;
import com.example.qxfw.common.entity.zy.*;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.dlqx.service.*;
import com.example.qxfw.rcyw.pojo.JobMake;
import com.example.qxfw.rcyw.service.JobMakeService;
import com.example.qxfw.ybzz.service.YbzzForeCastFinalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

@ApiIgnore
@Api(tags="电力气象-电力负荷预报")
@RestController
@CrossOrigin
@RequestMapping("/dlfhyb")
public class DlfhybController {

    @Autowired
    private MaxPowerLoadService maxPowerLoadService;

    @Autowired
    private PowerLoadHourService powerLoadHourService;

    @Autowired
    private YbzzForeCastFinalService ybzzForeCastFinalService;

    @Autowired
    private PowerRatioService powerRatioService;

    @Autowired
    private MaxPowerLoadFcstService maxPowerLoadFcstService;

    @Autowired
    private PowerLoadHourFcstService powerLoadHourFcstService;

    @Autowired
    private PowerProductService powerProductService;

    @Autowired
    private JobMakeService jobMakeService;

    @ApiOperation("获取电力负荷实况最新时间")
    @GetMapping("/getMaxTime")
    public SysResult getMaxTime(){
        List<MaxPowerLoad> maxTime = maxPowerLoadService.getMaxTime();
        return SysResult.success(maxTime);
    }

    @ApiOperation("获取电力负荷实况")
    @GetMapping("/getMaxPowerLoad")
    public SysResult getMaxPowerLoad(String dateChar){
        List<MaxPowerLoad> maxPowerLoads = maxPowerLoadService.listByDateChar(dateChar);
        return SysResult.success(maxPowerLoads);
    }

    @ApiOperation("获取电力逐小时负荷实况")
    @GetMapping("/getPowerLoadHour")
    public SysResult getPowerLoadHour(String dateChar1,String dateChar2){
        List<PowerLoadHour> powerLoadHours = powerLoadHourService.listByParams(dateChar1, dateChar2);
        return SysResult.success(powerLoadHours);
    }

    @ApiOperation("获取预报制作结果")
    @GetMapping("/getYbzzForecastFinal")
    public SysResult getYbzzForecast(String dateChar1,String dateChar2,String stationId){
        List<YbzzForecastFinal> ybzzForecastFinals = ybzzForeCastFinalService.listByParams(dateChar1, dateChar2, stationId);
        return SysResult.success(ybzzForecastFinals);
    }

    @ApiOperation("获取预报制作结果统计")
    @GetMapping("/getYbzzForecastFinal1")
    public SysResult getYbzzForecastFinal1(String dateChar1,String dateChar2,String stationId){
        List<YbzzForecastFinal> ybzzForecastFinals = ybzzForeCastFinalService.listByParams1(dateChar1, dateChar2, stationId);
        return SysResult.success(ybzzForecastFinals);
    }

    @ApiOperation("获取电力负荷预报系数")
    @GetMapping("/getPowerRatio")
    public SysResult getPowerRatio(String month){
        List<PowerRatio> powerRatios = powerRatioService.listByMonth(month);
        return SysResult.success(powerRatios);
    }

    @ApiOperation("获取最大电力负荷预报")
    @GetMapping("/getMaxPowerLoadFcst")
    public SysResult getMaxPowerLoadFcst(String dateChar,String timeChar,String nTimes){
        List<MaxPowerLoadFcst> maxPowerLoadFcsts = maxPowerLoadFcstService.listByParams(dateChar, timeChar, nTimes);
        return SysResult.success(maxPowerLoadFcsts);
    }

    @ApiOperation("更新最大电力负荷预报")
    @PostMapping("/updateMaxPowerLoadFcst")
    public SysResult updateMaxPowerLoadFcst(@RequestBody MaxPowerLoadFcst maxPowerLoadFcst){
        Integer rows = maxPowerLoadFcstService.update(maxPowerLoadFcst);
        return SysResult.success(rows);
    }

    @ApiOperation("保存最大电力负荷预报")
    @PostMapping("/saveMaxPowerLoadFcst")
    public SysResult saveMaxPowerLoadFcst(@RequestBody MaxPowerLoadFcst maxPowerLoadFcst){
        Integer rows = maxPowerLoadFcstService.save(maxPowerLoadFcst);
        return SysResult.success(rows);
    }

    @ApiOperation("获取电力逐小时负荷预报")
    @GetMapping("/getPowerLoadHourFcst")
    public SysResult getPowerLoadHourFcst(String dateChar){
        List<PowerLoadHourFcst> powerLoadHourFcsts = powerLoadHourFcstService.listByDateChar(dateChar);
        return SysResult.success(powerLoadHourFcsts);
    }

    @ApiOperation("更新电力逐小时负荷预报")
    @PostMapping("/updatePowerLoadHourFcst")
    public SysResult updatePowerLoadHourFcst(@RequestBody PowerLoadHourFcst powerLoadHourFcst){
        Integer rows = powerLoadHourFcstService.update(powerLoadHourFcst);
        return SysResult.success(rows);
    }

    @ApiOperation("获取电力逐小时负荷预报")
    @PostMapping("/savePowerLoadHourFcst")
    public SysResult savePowerLoadHourFcst(@RequestBody PowerLoadHourFcst powerLoadHourFcst){
        Integer rows = powerLoadHourFcstService.save(powerLoadHourFcst);
        return SysResult.success(rows);
    }

    @ApiOperation("获取电力产品")
    @GetMapping("/getPowerProduct")
    public SysResult getPowerProduct(String productName){
        List<PowerProduct> powerProducts = powerProductService.listByProductName(productName);
        return SysResult.success(powerProducts);
    }

    @ApiOperation("更新电力产品")
    @PostMapping("/updatePowerProduct")
    public SysResult updatePowerProduct(@RequestBody PowerProduct powerProduct){
        Integer rows = powerProductService.update(powerProduct);
        return SysResult.success(rows);
    }

    @ApiOperation("保存电力产品")
    @PostMapping("/savePowerProduct")
    public SysResult savePowerProduct(@RequestBody PowerProduct powerProduct){
        Integer rows = powerProductService.save(powerProduct);
        return SysResult.success(rows);
    }

    @ApiOperation("更新日常任务")
    @PostMapping("/updateJobmake")
    public SysResult updateJobMake(@RequestBody JobMake jobMake){
        Integer rows = jobMakeService.update(jobMake);
        return SysResult.success(rows);
    }


    @ApiOperation("通过时间点获取日电力负荷预报")
    @GetMapping("/selectByDateOfMaxPowerLoadFcst")
    public SysResult selectByDateOfMaxPowerLoadFcst(String date){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<MaxPowerLoadFcst> list = maxPowerLoadFcstService.selectByDateOfMaxPowerLoadFcst(datechar);
        return SysResult.success(list);
    }

}
